package service.impl.exec;

import entity.ExpireKey;
import entity.Result;
import service.ExecService;
import service.impl.ExpireKeyManageServiceImpl;

public class CommonServiceImpl implements ExecService {
    @Override
    public String exec(String[] data) {
        switch (data[1]){
            case "del":{
                //common del key
                del(data[2]);
            }
            case "keys":{
                //common keys *
                return keys(data[2]);
            }
            case "expire":{
                //common expire key mill
                String key = data[2];
                long mill = Long.valueOf(data[3]);
                if (get(key)==null){
                    return Result.KeyNotExist();
                }else {
                    //key存在
                    long timeStamp=System.currentTimeMillis()+1000*mill;
                    ExpireKey expireKey=new ExpireKey(key,timeStamp);
                    ExpireKeyManageServiceImpl.add(expireKey);
                }
                return Result.Success();
            }
        }
        return Result.Error();
    }

}
